/**
 * common util function 
 */

function getParams() {
   var idx = document.URL.indexOf('?');
   var params = new Array();

   if (idx != -1) {
      var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
      for (var i=0; i<pairs.length; i++) {
         var nameVal = pairs[i].split('=');
         params[nameVal[0]] = nameVal[1];
      }
   }
   return params;
}

function setTdElementText(elementId, text) {
   var e = document.getElementById(elementId);
   if( e != null) {
      e.firstChild.nodeValue = text;
   }
}

function setElementBgColor(elementId, color) {
   var e = document.getElementById(elementId);
   if(elementId != null) {
      e.style.backgroundColor = color;
   }
}

function setElementBackground(elementId, backGround) {
   var e = document.getElementById(elementId);
   if(e != null) {
      e.style.background = backGround;
   }
}

function setInnerHtml(elementId, html) {
   var e = document.getElementById(elementId);
   if(e != null) {
      e.innerHTML = html;
   }
}

function setImgSrc(elementId, src) {
   var e = document.getElementById(elementId);
   if(e != null) {
      e.src = src;
   }
}

function getBitrateImageTag(level) {
   if(level >= 0 && level < 6) {
      return "<img src=\"http://static.you2play.com/xl/images/pg_bar/SIGNAL_"+level+".png\" alt=\"\" width=\"57px\" height=\"41px\"/>";; 
   } else {
      return "";
   }
}

function replaceAll(source, searchValue, replaceValue) {
   var toIdx = source.indexOf(searchValue, idx);
   if(toIdx < 0) {
      return source;
   }
   var rtnVal = "";
   var idx = 0;
   while(toIdx > -1) {
      rtnVal += source.substring(idx, toIdx);
      rtnVal += replaceValue;
      idx = toIdx + searchValue.length;
      toIdx = source.indexOf(searchValue, idx);
   }
   rtnVal += source.substring(idx, source.length);
   return rtnVal;
}

function setElementVisibility(elementId, isVisible) {
   var e = document.getElementById(elementId);
   if(e != null) {
      if (isVisible) {e.style.visibility="";} else {e.style.visibility="hidden";}
   }
}

function setElementDisplay(elementId, isVisible) {
   var e = document.getElementById(elementId);
   if(e != null) {
      if (isVisible) {e.style.display="";} else {e.style.display="none";}
   }
}

function addEvent(object, eventStr, func) {
   try {
      object.addEventListener(eventStr, func, false);
   } catch (e) {
      alert("addEvent["+eventStr+"]["+func+"] ["+e.message+"]");
   }
}

function removeEvent(object, eventStr, func) {
   try {
      object.removeEventListener(eventStr, func);
   } catch (e) {
      alert("removeEvent["+eventStr+"]["+func+"] ["+e.message+"] ");
   }
}

function setKeyHelpAction(keyHelpId, activeFlag, action, innerHtml) {
   var kh = document.getElementById("kh_"+keyHelpId);
   if(kh != null) {
      if(activeFlag) {
         kh.onmouseover = new Function("processKeyHelpOver("+keyHelpId+");"); 
         kh.onmouseout = new Function("processKeyHelpOut("+keyHelpId+")");
         kh.onmousedown = new Function(action);
         setInnerHtml("kh_"+keyHelpId, innerHtml);
      } else {
         kh.onmouseover = "";
         kh.onmouseout = "";
         kh.onmousedown = "";
         setInnerHtml("kh_"+keyHelpId, "&nbsp;");
      }
   }
}

/**
 * version set
 */
var versionStr = "";
/**
 * keyHelpArea
 */

// fullModeCtrlView : 0 or 7 - hide full mode ctrl, 1~6 - show full mode ctrl,
var fullModeCtrlView = 0;

function processKeyHelpOver(elementId, prefix) {      
   //outFocusing     
   if(curMenu!=10){
      if(curMenu == menu.HOME){
         changeImage('play_now', 'url(http://static.you2play.com/xl/images/common/BTN_NORMAL.png)', 'left top');
      }
      zoomOut();
   }
   
   fullModeCtrlView = 1;
   if(prefix != null && prefix != 'undefined') {   
      document.getElementById(prefix+'kh_'+elementId).style.width = "197px";
      document.getElementById(prefix+'kh_'+elementId).style.height = "59px";
      setElementBackground(prefix+"kh_"+elementId,"url(http://static.you2play.com/xl/images/keyhelp/KEYHELP_FOCUS.png)");
      
   } else {
      if (document.getElementById('khImg'+elementId) == null || 
            document.getElementById('khImg'+elementId).style.visibility != 'hidden') { 
         
         document.getElementById('kh_'+elementId).style.width = "197px";
         document.getElementById('kh_'+elementId).style.height = "59px";
         setElementBackground("kh_"+elementId,"url(http://static.you2play.com/xl/images/keyhelp/KEYHELP_FOCUS.png)");
      }
   }
}

function processKeyHelpOut(elementId, prefix) {
   
   fullModeCtrlView = 1;
   if(prefix != null && prefix != 'undefined') {
      document.getElementById(prefix+'kh_'+elementId).style.width = "191px";
      document.getElementById(prefix+'kh_'+elementId).style.height = "56px";
      setElementBackground(prefix+"kh_"+elementId,"url(http://static.you2play.com/xl/images/keyhelp/KEYHELP_NORMAL.png)");
   } else {
      if (document.getElementById('kh_'+elementId) != null){
         document.getElementById('kh_'+elementId).style.width = "191px";
         document.getElementById('kh_'+elementId).style.height = "56px";
      }
      setElementBackground("kh_"+elementId,"url(http://static.you2play.com/xl/images/keyhelp/KEYHELP_NORMAL.png)");
   }
}

function processKeyHelp(actionId) {
   fullModeCtrlView = 1;
   switch(actionId) {
      case 'option' :
         //full screen mode auto??
         break;
      case 'full' :
         //alert('full screen');
         break;
      case 'scan' :
         //alert('scan screen');
         break;
      case 'back' :        
         window.history.back();
         break;
      case 'home' :
         window.NetCastReturn(VK_BACK);
         break;
      case 'exit' :
         //window.NetCastExit();
         alert("window.NetCastExit() is not recommended to use");
         break;
      case 'nextPage' :
      {
         if (pageNo+1 < dataCount/5) {clickArr('true');}
         break;
      } 
      case 'prevPage' :
      {
         if (pageNo > 0) {clickArr('false');}
         break;
      }
      default :
         break;
   }
}

var menuLevel = {"HOME": "Home", "FEATURED": "Featured", "MENU1" : "Menu 01", "MENU2" : "Menu 02", "MENU3" : "Menu 03", "MENU4" : "Menu 04" , "MENU5" : "Menu 05"};
var menu = {"HOME": 0, "FEATURED": 1, "MENU1" : 2, "MENU2" : 3, "MENU3" : 4, "MENU4" : 5 , "MENU5" : 6};
//var level = {"MENU":0, "PLAY":1, "THUMB":2, "NONE": 3};
var level = {"MENU":0, "PLAY":1, "THUMB":2, "NONE": 3, "BOTTOM_LINE" : 4};

var menuSize = 7;
var tabBlockSize = 5;
var tabNo = 0;
var contentTitle = "";

var curMenu = menu.HOME;
var beforeMenu = menu.HOME;
var curLevel = level.MENU;
var curFocus;
var displayMenu = menu.HOME;


function changeMenu() { 
   //jjw_add
   var tabCurMenu = curMenu;
   if(tabCurMenu>=tabBlockSize){
      tabCurMenu = curMenu%tabBlockSize;
   }  
   
   if (curMenu != beforeMenu) {
         
      if (beforeMenu == menu.HOME || beforeMenu == menu.MENU3 || beforeMenu == menu.MENU4) {
         if(beforeMenu>=tabBlockSize){
            beforeMenu = beforeMenu%tabBlockSize;
         }
         document.getElementById('menu'+beforeMenu).className = 'tabGray';
      }
      curFocus = 'menu' + curMenu;
   }
   menuFocused(tabCurMenu);
}


function menuFocused(menuNo) {
   //jjw_add      
   menuNo = tabNo*tabBlockSize+menuNo;
   if(curFocus!=null){     
      if(curFocus.substr(0,5) == "thumb"){zoomOut(0);} else if(curFocus == "play_now"){
         changeImage('play_now', 'url(http://static.you2play.com/xl/images/common/BTN_NORMAL.png)', 'left top');
      }
   }  

   document.getElementById('menu'+menu.HOME).className = 'tabGrayFirst';
   for(i=1; i<tabBlockSize; i++){
      document.getElementById('menu'+i).className = 'tabGray';
   }
   
   var tabCurMenu = menuNo;
   if(tabCurMenu>=tabBlockSize){
      tabCurMenu = menuNo%tabBlockSize;
   }  
      
   if (displayMenu == menu.HOME) {  
      if(menuNo == menu.HOME || menuNo == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
      } else if(menuNo == menu.FEATURED || menuNo == menu.MENU1 || menuNo == menu.MENU2){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuFirst';
      } else if(menuNo == menu.MENU3){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayEnd';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuFirst';
      } else if(menuNo == menu.MENU5){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';
      }
   } else if (displayMenu == menu.FEATURED) {
      if(menuNo == menu.HOME){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.FEATURED){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';      /////////////  
      } else if(menuNo == menu.MENU1 || menuNo == menu.MENU2){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.MENU3){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayEnd';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
      } else if(menuNo == menu.MENU5){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';
      } 
   } else if (displayMenu == menu.MENU1) {
      if(menuNo == menu.HOME){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.FEATURED){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';      
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.MENU1){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';      /////////////  
      } else if(menuNo == menu.MENU2){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.MENU3){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayEnd';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
      } else if(menuNo == menu.MENU5){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';
      } 
   } else if (displayMenu == menu.MENU2) {
      if(menuNo == menu.HOME){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.FEATURED){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';      
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.MENU1){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';   
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.MENU2){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';   /////////////  
      } else if(menuNo == menu.MENU3){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayEnd';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuMiddle';
      } else if(menuNo == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
      } else if(menuNo == menu.MENU5){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';
      } 
   } else if (displayMenu == menu.MENU3) {
      if(menuNo == menu.HOME){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
         document.getElementById('menu'+displayMenu).className = 'selectedMenuEnd';
      } else if(menuNo == menu.FEATURED){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';      
         document.getElementById('menu'+displayMenu).className = 'selectedMenuEnd';
      } else if(menuNo == menu.MENU1){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';   
         document.getElementById('menu'+displayMenu).className = 'selectedMenuEnd';
      } else if(menuNo == menu.MENU2){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';   
         document.getElementById('menu'+displayMenu).className = 'selectedMenuEnd';
      } else if(menuNo == menu.MENU3){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayEnd';      /////////////  
      } else if(menuNo == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
      } else if(menuNo == menu.MENU5){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';
      } 
   } else if (displayMenu == menu.MENU4) {
      if(menuNo == menu.HOME){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
      } else if(menuNo == menu.FEATURED){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';      
      } else if(menuNo == menu.MENU1){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';   
      } else if(menuNo == menu.MENU2){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';   
      } else if(menuNo == menu.MENU3){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayEnd';      
      } if(menuNo == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst'; /////////////  
      } else if(menuNo == menu.MENU5){       
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';
         if(tabNo==1){
            document.getElementById('menu'+0).className = 'selectedMenuFirst';
         }        
      } 
   } else if (displayMenu == menu.MENU5) {
      if(menuNo == menu.HOME){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst';
      } else if(menuNo == menu.FEATURED){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';      
      } else if(menuNo == menu.MENU1){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';   
      } else if(menuNo == menu.MENU2){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';   
      } else if(menuNo == menu.MENU3){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayEnd';      
      } if(menuNo == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayFirst'; 
         if(tabNo==1){
            document.getElementById('menu'+1).className = 'selectedMenuMiddle';
         }
      } else if(menuNo == menu.MENU5){       
         document.getElementById('menu'+tabCurMenu).className = 'focusedGrayMiddle';   /////////////                 
      } 
   }
   curMenu = menuNo;    
   curLevel = level.MENU;  
   //setKeyHelpArea();
}

function menuOutFocus(menuNo, pageFrom) {
   
   var tabMenuNo = Number(tabNo*tabBlockSize+menuNo);
   
   if (tabMenuNo == menu.HOME) {
      if (pageFrom == menu.HOME) {
         document.getElementById('menu'+menuNo).className = 'selectedMenuFirst';
      } else {
         document.getElementById('menu'+menuNo).className = 'tabGrayFirst';
      }
   } else if (tabMenuNo == menu.FEATURED) {
      if (pageFrom == menu.FEATURED) {       
         document.getElementById('menu'+menuNo).className = 'selectedMenuMiddle';
         document.getElementById('menu'+menu.HOME).className = 'tabGrayFirst';
      } else {
         document.getElementById('menu'+menuNo).className = 'tabGray';
      }
   } else if (tabMenuNo == menu.MENU1) {
      if (pageFrom == menu.MENU1) {       
         document.getElementById('menu'+menuNo).className = 'selectedMenuMiddle';
         document.getElementById('menu'+menu.HOME).className = 'tabGrayFirst';
      } else {
         document.getElementById('menu'+menuNo).className = 'tabGray';
      }
   } 
   else if (tabMenuNo == menu.MENU2) {
      if (pageFrom == menu.MENU2) {       
         document.getElementById('menu'+menuNo).className = 'selectedMenuMiddle';
         document.getElementById('menu'+menu.HOME).className = 'tabGrayFirst';
      } else {
         document.getElementById('menu'+menuNo).className = 'tabGray';
      }     
   } else if (tabMenuNo == menu.MENU3) {
      if (pageFrom == menu.MENU3) {       
         document.getElementById('menu'+menuNo).className = 'selectedMenuEnd';
         document.getElementById('menu'+menu.HOME).className = 'tabGrayFirst';
      } else {
         document.getElementById('menu'+menuNo).className = 'tabGray';
      }  
   } else if (tabMenuNo == menu.MENU4) {
      if (pageFrom == menu.MENU4) {    
         document.getElementById('menu'+menuNo).className = 'selectedMenuFirst';       
      } else {
         document.getElementById('menu'+menuNo).className = 'tabGrayFirst';
      }     
   } else if (tabMenuNo == menu.MENU5) {
      if (pageFrom == menu.MENU5) {       
         document.getElementById('menu'+menuNo).className = 'selectedMenuMiddle';         
      } else {
         document.getElementById('menu'+menuNo).className = 'tabGray';
      }
   }    
}

function changeImage(id, img, position) { 
   if(curFocus!=null){
      if(curFocus.substr(0,5) == "thumb"){zoomOut(0);} else if(curFocus.substr(0,4) == "menu" && event.keyCode != VK_UP){    
         var menuNo = curFocus.charAt(4);
         var pageFrom = displayMenu;      
         menuOutFocus(menuNo, pageFrom);
      }
   }
      
   document.getElementById(id).style.background = img;
   document.getElementById(id).style.backgroundRepeat = 'no-repeat';
   document.getElementById(id).style.backgroundPosition = position;
   
   if(tabNo==0){
      if (id == 'play_now' && img == 'url(http://static.you2play.com/xl/images/common/BTN_FOCUS.png)') {
         document.getElementById('menu'+menu.HOME).className = 'selectedMenuFirst';
      }
   } else if(tabNo == 1){     
      if (id == 'play_now' && img == 'url(http://static.you2play.com/xl/images/common/BTN_FOCUS.png)') {
         document.getElementById('menu'+menu.HOME).className = 'tabGrayFirst';
      }     
   }  
}

var pageNo = 0;
var curIndex = 0;

function zoomOut(index) {
   document.getElementById('thumbFocus').style.visibility = 'hidden';
   document.getElementById('focusFrame').style.visibility = 'hidden';
   document.getElementById('thumbTimeInfoFocus').style.visibility = 'hidden';
   
}

function zoomIn(index) {   
   contentTitle = title[pageNo * 5 + index];
   if(curFocus == "play_now"){
      changeImage('play_now', 'url(http://static.you2play.com/xl/images/common/BTN_NORMAL.png)', 'left top');
   }
   
   curIndex = index;
   document.getElementById('thumbFocus').style.visibility = 'visible';
   document.getElementById('focusFrame').style.visibility = 'visible';
   document.getElementById('thumbTimeInfoFocus').style.visibility = 'visible';
   
   document.getElementById('thumbFocus').style.left = 85 + index * 220 + 'px';
   document.getElementById('focusFrame').style.left = 85 + index * 220 + 'px';
   document.getElementById('thumbTimeInfoFocus').style.left = 218 + index * 220 + 'px';
   
   document.getElementById('thumbTitle').innerHTML = title[pageNo * 5 + index];
   document.getElementById('thumbTimeFocus').innerHTML = time[pageNo * 5 + index];
   
   if(contentTitle.length>21){
      contentTitle = contentTitle.substr(0,20)+"..";
   }
   document.getElementById('thumbTitle').innerHTML = contentTitle;//title[pageNo * 5 + index];
   document.getElementById('thumbTimeFocus').innerHTML = time[pageNo * 5 + index];

   var tabCurMenu = curMenu;
   if(tabCurMenu>=tabBlockSize){
      tabCurMenu = curMenu%tabBlockSize;
   }  
   
   
   if (displayMenu == menu.HOME) {  
      if(curMenu == menu.HOME){
         document.getElementById('menu'+tabCurMenu).className = 'selectedMenuFirst';
      } else if(curMenu == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'tabGrayFirst';
      } else{
         document.getElementById('menu'+tabCurMenu).className = 'tabGray';
      }
   } else if (displayMenu == menu.FEATURED) {   
      if(curMenu == menu.FEATURED){
         document.getElementById('menu'+tabCurMenu).className = 'selectedMenuMiddle';
      } else if(curMenu == menu.HOME || curMenu == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'tabGrayFirst';
      } else{
         document.getElementById('menu'+tabCurMenu).className = 'tabGray';
      }
   } else if (displayMenu == menu.MENU1) {            
      if(curMenu == menu.MENU1){
         document.getElementById('menu'+tabCurMenu).className = 'selectedMenuMiddle';
      } else if(curMenu == menu.HOME || curMenu == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'tabGrayFirst';
      } else{
         document.getElementById('menu'+tabCurMenu).className = 'tabGray';
      }
   } else if (displayMenu == menu.MENU2) {            
      if(curMenu == menu.MENU2){
         document.getElementById('menu'+tabCurMenu).className = 'selectedMenuMiddle';
      } else if(curMenu == menu.HOME || curMenu == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'tabGrayFirst';
      } else{
         document.getElementById('menu'+tabCurMenu).className = 'tabGray';
      }
   } else if (displayMenu == menu.MENU3) {            
      if(curMenu == menu.MENU3){
         document.getElementById('menu'+tabCurMenu).className = 'selectedMenuEnd';
      } else if(curMenu == menu.HOME || curMenu == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'tabGrayFirst';
      } else{
         document.getElementById('menu'+tabCurMenu).className = 'tabGray';
      }
   } else if (displayMenu == menu.MENU4) {            
      if(curMenu == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'selectedMenuFirst';
      } else if(curMenu == menu.HOME){
         document.getElementById('menu'+tabCurMenu).className = 'tabGrayFirst';
      } else{
         document.getElementById('menu'+tabCurMenu).className = 'tabGray';
      }
   } else if(displayMenu == menu.MENU5){
      if(curMenu == menu.MENU5){
         document.getElementById('menu'+tabCurMenu).className = 'selectedMenuMiddle';
      } else if(curMenu == menu.HOME || curMenu == menu.MENU4){
         document.getElementById('menu'+tabCurMenu).className = 'tabGrayFirst';
      } else{
         document.getElementById('menu'+tabCurMenu).className = 'tabGray';
      }
   }
   
   curFocus = 'thumb'+index;
   curLevel = level.THUMB;
   //setKeyHelpArea();  
}

function clickPlay(index) {
   if (index == -1) {
      index = curIndex;
   }
   
   location.href = 'play.html?id='+(pageNo*5 + index);
}

function getCurrentMenu(){
   var curLocation = window.location.href;
   var curMenuNo = -1;
   if(curLocation.indexOf("homelist.html") > -1){curMenuNo = menu.HOME;}
   else if(curLocation.indexOf("featuredlist.html") > -1){curMenuNo = menu.FEATURED;}
   else if(curLocation.indexOf("menu1.html") > -1){curMenuNo = menu.MENU1;}
   else if(curLocation.indexOf("menu2.html") > -1){curMenuNo = menu.MENU2;}
   else if(curLocation.indexOf("menu3.html") > -1){curMenuNo = menu.MENU3;}
   else if(curLocation.indexOf("menu4.html") > -1){curMenuNo = menu.MENU4;}
   else if(curLocation.indexOf("menu5.html") > -1){curMenuNo = menu.MENU5;}
   return curMenuNo;
}

function movePage(menuNo) {
   
   menuNo = Number(tabNo*tabBlockSize+menuNo);
   
   var   curMenuNo = getCurrentMenu();
   if(curMenuNo != -1 && curMenuNo == menuNo){return;}

   var page;
   if (menuNo == menu.HOME) {
      displayMenu = menu.HOME;
      page = "homelist.html";
   } else if (menuNo == menu.FEATURED) {
      displayMenu = menu.FEATURED;
      page = "featuredlist.html";
   } else if (menuNo == menu.MENU1) {
      displayMenu = menu.MENU1;
      page = "menu1.html";
   } else if (menuNo == menu.MENU2){
      displayMenu = menu.MENU2;
      page = "menu2.html";
   } else if (menuNo == menu.MENU3){
      displayMenu = menu.MENU3;
      page = "menu3.html";
   } else if(menuNo == menu.MENU4){
      displayMenu = menu.MENU4;
      page = "menu4.html";
   } else if(menuNo == menu.MENU5){
      displayMenu = menu.MENU5;
      page = "menu5.html";
   }
   location.href = page;
}

function clickArr(right) {
   if (right == 'true') {
      pageNo++;
      if (dataCount > (pageNo+1) * 5) {
         document.getElementById('rightArr').style.visibility = 'visible';
      } else {
         document.getElementById('rightArr').style.visibility = 'hidden';
      }
      document.getElementById('leftArr').style.visibility = 'visible';
   } else {
      pageNo--;
      if (pageNo == 0) {
         document.getElementById('leftArr').style.visibility = 'hidden';
      } else {
         document.getElementById('leftArr').style.visibility = 'visible';
      }
      document.getElementById('rightArr').style.visibility = 'visible';
   }
   setImage();
   //setKeyHelpArea();
}

function setImage() {

}

function setKeyHelpArea() {
   if (curLevel == level.THUMB) {
      
      if (pageNo > 0) {
         setKeyHelpAction("1", true, "processKeyHelp('prevPage')", "<img id='khImg1' src='http://static.you2play.com/xl/images/keyhelp/KEYHELP_ICON_CH_UP.png' style='vertical-align: middle;'> Prev. page");
      } else {
         setKeyHelpAction("1", false, null, null);
      }
      
      if (pageNo+1 < dataCount/5) {
         setKeyHelpAction("2", true, "processKeyHelp('nextPage')", "<img id='khImg2' src='http://static.you2play.com/xl/images/keyhelp/KEYHELP_ICON_CH_DOWN.png' style='vertical-align: middle;'> Next page");
      } else {
         setKeyHelpAction("2", false, null, null);
      }
      processKeyHelpOut(1);
      processKeyHelpOut(2);
   } else {
      processKeyHelpOut(1);
      processKeyHelpOut(2);
      setKeyHelpAction("1", false, null, null);
      setKeyHelpAction("2", false, null, null);
   }  
}

function topMenuLeft(){
   tabNo = 0;  
   document.getElementById("menu0").innerHTML = menuLevel.HOME;
   document.getElementById("menu0").className = 'tabGrayFirst';
      
   document.getElementById("menu1").innerHTML = menuLevel.FEATURED;  
   document.getElementById("menu1").style.visibility = "visible";
   
   document.getElementById("menu2").innerHTML = menuLevel.MENU1;  
   document.getElementById("menu2").style.visibility = "visible";
   
   document.getElementById("menu3").innerHTML = menuLevel.MENU2;  
   document.getElementById("menu3").style.visibility = "visible";
   
   document.getElementById("menu4").innerHTML = menuLevel.MENU3;  
   document.getElementById("menu4").style.visibility = "visible";
   
   document.getElementById("menu7").style.visibility = "visible";

   document.getElementById("menu8").style.visibility = "hidden";
   
}

function topMenuRight(){
   tabNo = 1;
   curMenu = menu.MENU4;
   document.getElementById("menu0").innerHTML = menuLevel.MENU4;  
   if(displayMenu == menu.MENU5){
      //curMenu = menu.MENU5; 
      document.getElementById("menu0").className = "tabGrayFirst";
      document.getElementById("menu1").className = "selectedMenuMiddle";
   } else{
      document.getElementById("menu0").className = "focusedGrayFirst";
   }
   
   
   if(displayMenu == menu.FEATURED){
      document.getElementById("menu1").className = "tabGray";
   }
   document.getElementById("menu1").style.visibility = "visible"; 
   document.getElementById("menu1").innerHTML = menuLevel.MENU5;
         
   document.getElementById("menu2").style.visibility = "hidden";  
   document.getElementById("menu2").innerHTML = "";
   
   document.getElementById("menu3").style.visibility = "hidden";     
   document.getElementById("menu3").innerHTML = "";
   
   document.getElementById("menu4").style.visibility = "hidden";  
   document.getElementById("menu4").innerHTML = "";

   document.getElementById("menu7").style.visibility = "hidden";
   document.getElementById("menu8").style.visibility = "visible";
   
}

function getUserAgent() {
   userAgent = new String(navigator.userAgent);
   var LG_TV = document.getElementById("key_tv");
   var LG_TV_BG = document.getElementById("key_tv_bg");
   var LG_MEDIA = document.getElementById("key_bdp");
   var LG_MEDIA_BG = document.getElementById("key_bdp_bg");
   if (userAgent.search("LG NetCast.TV") > -1 ) {  
      if(LG_TV_BG!=null){
         LG_TV_BG.style.display = "";
      }
      if(LG_TV){
        LG_TV.style.display = "";      
     }
      versionStr = "v 1.006 (20110310) -TV"; 
   } else if (userAgent.search("LG NetCast.Media") > -1 ){
      if(LG_MEDIA_BG!=null){
         LG_MEDIA_BG.style.display = "";
      }
      if(LG_MEDIA){
        LG_MEDIA.style.display = "";
      }
      versionStr = "v 1.006 (20110310) -BDP";
   } else { 
     // alert("other browser");           
   }
}
